﻿package vklib
{
	import flash.display.LoaderInfo;	
	/**
	 * ...
	 * @author apisoc@gmail.com
	 */
	internal class GuiFactory implements IVkGuiFactory
	{
		private var _classes:Object = {
			MainMenu:null,
			ComboBox:null,
			ListBox:null,
			RoundButton:null,
			SquareButton:null,
			LinkButton:null,
			LightButton:null,
			Box:null,
			CheckBox:null,
			RadioButton:null,
			RadioButtonsGroup:null,
			ScrollBar:null,
			InputField:null,
			Pagination:null,
			Utils:null
		};
		
		public function GuiFactory(data:LoaderInfo)
		{
			for (var name:String in _classes)
				_classes[name] = data.applicationDomain.getDefinition('vk.gui.'+name) as Class;
		}

		
		public function classByName(name:String):Class
		{
			return _classes[name];
		}
		
		public function createMainMenu(lazyMode:Boolean = false):*
		{
			return new _classes.MainMenu(VkApi.instance.wrapper, lazyMode);
		}
		
		public function createComboBox(x:int, y:int, width:uint):*
		{
			return new _classes.ComboBox(VkApi.instance.wrapper, x, y, width);
		}

		public function createListBox(x:int, y:int, width:uint):*
		{
			return new _classes.ListBox(x, y, width);
		}

		public function createRoundButton(label:String, x:int, y:int, type:uint = 1):*
		{
			return new _classes.RoundButton(label, x, y, type);
		}

		public function createSquareButton(label:String, x:int, y:int, type:uint = 1):*
		{
			return new _classes.SquareButton(label, x, y, type);
		}

		public function createLinkButton(label:String, x:int, y:int, font_size:uint = 11, width:uint = 0, height:uint = 0):*
		{
			return new _classes.LinkButton(label, x, y, font_size, width, height);
		}

		public function createLightButton(label:String, x:int, y:int, width:uint, colors:Array, align:uint = 0, font_size:uint = 11, margins:uint = 4):*
		{
			return new _classes.LightButton(label, x, y, width, colors[0], colors[1], colors[2], colors[3], align, font_size, margins);
		}

		public function createBox(title:String, content:*, y:int, width:uint, buttons:Array):*
		{
			return new _classes.Box(title, content, y, width, buttons);
		}

		public function createCheckBox(title:String, x:int, y:int):*
		{
			return new _classes.CheckBox(title, x, y);
		}

		public function createRadioButtonsGroup(x:int, y:int):*
		{
			return new _classes.RadioButtonsGroup(x, y);
		}
		
		public function createScrollBar(x:int, y:int, height:int):*
		{
			return new _classes.ScrollBar(x, y, height);
		}
		
		public function createInputField(x:uint, y:uint, width:uint, linesCount:uint = 1, editable:Boolean = true, border:Boolean = true):*
		{
			return new _classes.InputField(x, y, width, linesCount, editable, border);
		}
		
		public function createPagination(totalCount:uint, x:uint, y:uint, height:uint = 0, type:uint = 0, pagesVisible:uint = 2, elemsOnPage:uint = 10):*
		{
			return new _classes.Pagination(totalCount, x, y, height, type, pagesVisible, elemsOnPage);
		}

		public function addText(s:String, x:int, y:int, container:* = null, text_color:uint = 0, text_format:uint = 0x0010, width:uint = 0, height:uint = 0, font_size:uint = 11):*
		{
			var ret:* = _classes.Utils.addText(x, y, width, font_size, s, text_color, text_format, height);
			if (container) container.addChild(ret);
			return ret;
		}
	}
}